package com.deepclassifieds.daas.api.builder;

import com.deepclassifieds.daas.api.xsd.Column;
import com.deepclassifieds.daas.api.xsd.Columns;
import com.deepclassifieds.daas.common.Builder;
import com.deepclassifieds.daas.common.Name;
import com.deepclassifieds.daas.common.Reject;

public class ColumnsBuilder implements Builder<Columns> {
	
	private final Columns columns;
	
	public ColumnsBuilder() {
		this.columns = new Columns();
	}
	
	public ColumnsBuilder(Columns columns) {
		Reject.ifNull(columns);
		this.columns = new Columns();
		this.columns.getColumn().addAll(columns.getColumn());
	}

	@Override
	public Columns build() {
		return columns;
	}

	public Column createAndAddColumn(Name columnName, String columnValue) {
		Reject.ifNull(columnName);
		Column column = new Column();
		column.setName(columnName.toString());	
		column.setValue(columnValue);
		column.setNull(columnValue == null);
		columns.getColumn().add(column);
		return column;
	}

}
